<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TMI</title>

<script type="text/javascript">
<%--============================= 전역변수 선언 ==========================--%>

 var rowCnt = 1;
 //<!--img src='/images/web/bkn_zoom.gif' aligh='right' id='customerPop' onclick='customerPopCall(this, \"S\");'-->
 var dynamicAddRow = "<tr id='dynamicDetailAddRow'>"
                    +"<td width='5%' align='center'>New<input type='hidden' id='rowId' name='rowId' value='1'/><input type='hidden' id='rowStatus' name='rowStatus' value='I'/></td>"
                    +"<td width='13%' ><input type='text' class='inST70' id='returnDate' name='returnDate'/></td>"
                    +"<td width='15%' ><input type='hidden' class='inSTR95' name='goodsCode'  />"
                    +"<input type='text' class='inSTR80' name='goodsName'  /><img src='/images/web/bkn_zoom.gif' aligh='right' id='returnProductPop' onclick='onReturnProductPopup(this);'></td>"
                    +"<td width='10%' ><input type='text' class='inSTR90' name='batchNo'  /></td>"
                    +"<td width='8%' ><input type='text' class='inSTR90' name='returnQty'  /><input type='hidden' class='inSTR95' name='mawb'  /><input type='hidden' class='inSTR95' name='hawb'  /></td>"
                    +"<td width='15%' ><input type='hidden' class='inSTR95' name='endUser'  />"
                    +"<input type='text' class='inSTR90' name='endUserName'  /></td>"
                    +"<td width='10%' ><input type='hidden' class='inSTR95' name='cause'  /><input type='text' class='inSTR95' name='causeText'  /></td>"
                    +"<td width='7%' ><input type='text' class='inSTR95' name='realsedQty'  /></td>"
                    +"<td align='center' width='7%'><img onclick='deleteTmpRow(this);' src='images/web/ic_x.gif' alt='Delete' id='onDelete'/></td>"    //행 추가후  삭제 버튼 추가
                    +"</tr>";
var popType ="";
    /************************************************************************/
    /*                          Onload function                             */
    /************************************************************************/

    $().ready(function() {
       
        <%-- outDetailTable에입력항목 생성 --%>
        $("table[id='outDetailTable']").append(dynamicAddRow);  // 전역변수로 잡아둔 값 셋팅
        $("#returnProductPopDetailHidden tr").remove();
        <%-- 달력 --%>
        calendar.makeCalender("sReturnStartDate");
        calendar.makeCalender("sReturnEndDate");
        calendar.makeCalender("pop_disDate");
        calendar.makeCalender("returnDate");
        calendar.makeCalender("pop_returnDate");
        
        if($("#roleId").val() == "3"){
            $("#sEndUserPop").attr("style", "display:none");
            $("#sMessrsPop").attr("style", "display:none");
            $("#productPop").attr("style", "display:none");
            $("#bo_btnS").attr("style", "display:none");
            $("#bo_btn").attr("style", "display:none");
            $("#bo_btn_add").attr("style", "display:none");
        }
        
        var keyparam = '${returnDate}';
        var keyparam2 = '${goodsCode}';
        var keyparam3 = '${batchNo}';
        var keyparam4 = '${goodsName}';
        if(keyparam != null && keyparam != ""){
        	$("#sGoodsCode").val(keyparam2);
            $("#sGoodsName").val(keyparam4);
            
            $("#sReturnStartDate").val(keyparam);
            $("#sReturnEndDate").val(keyparam); 
            $("#lotNo").val(keyparam3); 
        	view();
        }  
        
        <%-- 버튼설정 --%>
        $("#btnSearch").bind("click",function(){       
            view();
        });
        
        /* textarea 체크 */
        $("#pop_remark").bind("keyup",function(){
            textAreaKyUp(this);  //조회 직후에도 호출해야해서 function 으로 뺌.. 
        });
        
        /* textarea 체크 */
        $("#pop_disRemark").bind("keyup",function(){
            textAreaKyUp2(this);  //조회 직후에도 호출해야해서 function 으로 뺌.. 
        });
        
        /* 초기화버튼 */
        $("#reSetBtn").bind("click",function(){
              $("form[name='outFrm']").each(function(){
                    this.reset();
              });
              //reSetValidete(); //벨류데이션 체크 초기화;
              $("#cnt").html("(0 / ");  // textarea 초기화
              $("#saveStatus").val("SAVE");     //신규 입력 상태로 변경
              rowCnt = 1;
              $("#returnProductPopDetailHidden tr").remove();
              $("table[id='outDetailTable']").empty().append(dynamicAddRow); // 지운 후 다시 입력항목 셋팅.. (css상 span id로하면 디자인깨짐, .html 로 하면 그리드 제목 까지 해줘야해서 귀찮음.. , 조회후에는 지워만주자)
              calendar.makeCalender("returnDate");
        });

        
        /* DETAIL ROW 행추가 버튼 설정 */
        $("#detailAddRow").bind("click",function(){
            /*if($("table[id='outDetailTable'] #rowStatus").val() == "I"){
                alert("Save after Add");
                return false;
            }*/
        	rowCnt++;
        	 var dynamicAddRowTwo = "<tr id='dynamicDetailAddRow'>"
                 +"<td width='5%' align='center'>new<input type='hidden' id='rowId' name='rowId' value='"+rowCnt+"'/><input type='hidden' id='rowStatus' name='rowStatus' value='I'/></td>"
                 +"<td width='13%' ><input type='text' class='inST70' name='returnDate' id='returnDate"+rowCnt+"'/></td>"
                 +"<td width='15%' ><input type='hidden' class='inSTR95' name='goodsCode'  />"
                 +"<input type='text' class='inSTR80' name='goodsName'  /><img src='/images/web/bkn_zoom.gif' aligh='right' id='returnProductPop' onclick='onReturnProductPopup(this);'></td>"
                 +"<td width='10%' ><input type='text' class='inSTR90' name='batchNo'  /></td>"
                 +"<td width='8%' ><input type='text' class='inSTR90' name='returnQty'  /><input type='hidden' class='inSTR95' name='mawb'  /><input type='hidden' class='inSTR95' name='hawb'  /></td>"
                 +"<td width='15%' ><input type='hidden' class='inSTR95' name='endUser'  />"
                 +"<input type='text' class='inSTR90' name='endUserName'  /></td>"
                 +"<td width='10%' ><input type='hidden' class='inSTR95' name='cause'  /><input type='hidden' class='inSTR95' name='remark'  /><input type='text' class='inSTR95' name='causeText'  /></td>"
                 +"<td width='7%' ><input type='text' class='inSTR95' name='realsedQty'  /></td>"
                 +"<td align='center' width='7%'><img onclick='deleteTmpRow(this);' src='images/web/ic_x.gif' alt='Delete' id='onDelete'/></td>"    //행 추가후  삭제 버튼 추가
                 +"</tr>";
                 
            $("table[id='outDetailTable']").prepend(dynamicAddRowTwo);  // 전역변수로 잡아둔 값 셋팅
            calendar.makeCalender("returnDate"+rowCnt); 
        });
        
        /* 저장버튼 */
        $("#saveBtn").bind("click",function(){  
        	var rowDetailIdTmp = "";
        	var rowDetailIdCnt = "";
        	var rowIdTmp = "";
        	var rowIdCnt = "";
        	$("[name=rowDetailId]").each(function(){
        		rowDetailIdTmp = $(this).val();
        		rowDetailIdCnt = $("[name=rowDetailId]").index(this);
        		$("[name=rowId]").each(function(){
        			rowIdTmp = $(this).val();
        			rowIdCnt = $("[name=rowId]").index(this);
        			if(rowDetailIdTmp == rowIdTmp){                         
        				$("[name=returnDateDetail]").eq(rowDetailIdCnt).val($("[name=returnDate]").eq(rowIdCnt).val());
        				$("[name=causeDetail]").eq(rowDetailIdCnt).val($("[name=cause]").eq(rowIdCnt).val());
        				$("[name=endUserDetail]").eq(rowDetailIdCnt).val($("[name=endUser]").eq(rowIdCnt).val());
        			}
        		});
                /*if($(this).val() == rowId){
                    var valCnt = $("[name=rowDetailId]").index(this);
                    $(this).parent().parent().remove(); 
                }*/
            });
            $("form[name='outFrm']").submit();
        });
        
        /* 삭제버튼 */
        $("#delBtn").bind("click",function(){       
            onDel();
        });

        /* 메인폼 저장 서브밋 */
        $("form[name='outFrm']").ajaxForm({
            dataType: "json",
            beforeSerialize: function($form, options) {
                //return $("form[name='outFrm']").valid();  jquery 벨류데이션 플러그인 사용시
                 if( !validation() ){       //화면 항목 점검 시작
                    return false;
                }
                 if(!confirm("Save?")){
                    return false;
                 }
            },
            success:function(data) {
               if(data.result == true){
                   alert("Complete the save");
                   view($("#outInvoice").val());  //조회 데이터 맵핑 펑션
               }               
           },
           error:function(){alert("error!!");}
        }); 
        
    });
        
    /************************************************************************/
    /*                          textarea 글자 수 체크                       */
    /************************************************************************/
    /* textarea 체크 */
    var oldStr;
    function textAreaKyUp(obj){
        var str = obj.value;
        if(str.length <= 1000){
            oldStr = str;
            contents = "("+str.length+" / ";
            $("#cnt").html(contents);
        }else{
            alert("Limited string has been exceeded.");
            $("#pop_remark").val(oldStr);
        }
    };
    
    /************************************************************************/
    /*                          textarea 글자 수 체크                       */
    /************************************************************************/
    /* textarea 체크 */
    var oldStr;
    function textAreaKyUp2(obj){
        var str = obj.value;
        if(str.length <= 1000){
            oldStr = str;
            contents = "("+str.length+" / ";
            $("#disCnt").html(contents);
        }else{
            alert("Limited string has been exceeded.");
            $("#pop_disRemark").val(oldStr);
        }
    };
    
    /************************************************************************/
    /*                          조회                                        */
    /************************************************************************/
    /* 조회 펑션 */
    function view(){
        $.post(
                '/getReturnProductView.json', {
                sReturnStartDate : $("#sReturnStartDate").val(),
                sReturnEndDate : $("#sReturnEndDate").val(),
                messrs : $("#sMessrs").val(),
                goodsCode : $("#sGoodsCode").val(),
                batchNo : $("#lotNo").val(),
                sReturnEndUser : $("#sReturnEndUser").val()
                },
            function(data) {
                $("#returnProductPopDetailHidden tr").remove();
                searchDataMaping(data);    //DATA맵핑 
            });
    }

    /************************************************************************/
    /*                          Grid ROW 삭제                               */
    /************************************************************************/ 
    /* ReturnProductDetail 삭제 펑션 */
    function delReturnProductDetail(returnNo){
        $.post(
                '/delReturnProductDetail.json', {  
                returnNo : returnNo
               },
            function(data) {
               if(data.result == true){
                   alert("Deleted.....!");
                   view();
               }else{
                   alert("ERROR!");
               }  
            });
    }

    /************************************************************************/
    /*                          Grid Row Update                             */
    /************************************************************************/
    /* detail update*/
    function modifyReturnProductDetail(){
        if(confirm("Update?")){
            $.post("/modifyReturnProductDetail.json",{
                returnNo      : $("#pop_returnNo").val(),
                returnDate      : $("#pop_returnDate").val(),
                returnEndUserName      : $("#pop_returnEndUserName").val(),
                returnEndUser      : $("#pop_returnEndUser").val(),
                realsedQty      : $("#pop_realsedQty").val(),
                qty      : $("#pop_qty").val(),
                qrYn      : $("#pop_qrYn").val(),
                cause      : $("#pop_cause").val(),
                remark      : $("#pop_remark").val(),
                disRemark      : $("#pop_disRemark").val(),
                disDate      : $("#pop_disDate").val()
            
            },function(data){
                if(data.result == true){
                    $("#viewDialog").dialog("close");
                    view();
                }
            });
        }
    }

    /************************************************************************/
    /*                          조회된 DATA MAPPING                         */
    /************************************************************************/
    /* searchData 맵핑 */
    function searchDataMaping(data){
        var val = "";         
        //하단 그리드 맵핑
        var contents = "";
        var tdTmp = "";
        $.each(data.resultDetailList, function(index){  // List로 받아온값 (여러건)
        	if($("#roleId").val() == "3"){
                tdTmp = "";
            }else{
                tdTmp = "<img src='images/web/ic_up.gif' alt='Update' id='onUpdateDetail' onclick='viewDialogOpen("+this.returnNo+" , \""+this.returnDate+"\",\""+this.returnEndUserName+"\",\""+this.returnEndUser+"\",\""+this.qty+"\",\""+this.qty2+"\",\""+this.stockQty+"\",\""+this.qrYn+"\",\""+this.returnCode+"\",\""+this.disDate+"\",\""+index+"\");' />"
                +'<img src="images/web/ic_x.gif" alt="Delete" id="onDeleteDetail" onclick="delReturnProductDetail('+this.returnNo+')" />'+'</td>';
            }
            //(Detail 테이블에 조회결과 입히기 jquery말고 그냥 onclick 걸어줌.. (조회 후 del 번튼에 key값 param변수로 입력)
            var rowNum = index+1;            
            contents += "<tr style='cursor:pointer' id='dynamicDetailSearchRow"+rowNum+"' onclick='rowSelect(this, \""+index+"\");'>"   
                +'<td align="center" width="5%">'+rowNum+'</td>'
                +'<td align="center" width="13%">'+this.returnDate+'</td>'
                +'<td align="left"   width="15%">'+this.goodsName+'</td>'
                +'<td align="center" width="10%">'+this.batchNo+'</td>'
                +'<td align="center"  width="8%">'+this.qty+'</td>'  
                +'<td align="center"  width="15%">'+this.returnEndUserName+'</td>' 
                +'<td align="center"   width="10%">'+this.returnName+'</td>' 
                +'<td align="center"  width="7%">'+this.stockQty+'</td>' 
                +'<td align="center"  width="7%"><input type="hidden" name="remarkTmp" id="remarkTmp" value="'+this.remark+'"><input type="hidden" name="disRemarkTmp" id="disRemarkTmp" value="'+this.disRemark+'"><input type="hidden" name="qty2" id="qty2" value="'+this.qty2+'">'
                +tdTmp
                +"</tr>";     
        });
        $("table[id='outDetailTable']").empty().append(contents);  // 조회 값 뿌리기
        $("table[id='outDetailTable'] tr:eq(0)").click();
        $("#saveStatus").val("UPDATE"); // 상태값 UPDATE로 변경
        
    }
    
    function rowSelect(obj, index){     
        $("#outDetailTable tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
        $("#remark").val($("[name=remarkTmp]").eq(index).val());
    }
    
    /************************************************************************/
    /*                          Grid 추가한 Row 삭제                        */
    /************************************************************************/
    /* 사용자가 추가한 행 삭제 */
    function deleteTmpRow(obj){
        //alert($(obj).parent().parent().parent().parent());
        var rowId = $("[name=rowId]").eq($("img[id='onDelete']").index(obj)).val();
        $("[name=rowDetailId]").each(function(){
        	if($(this).val() == rowId){
        		var valCnt = $("[name=rowDetailId]").index(this);
        		$(this).parent().parent().remove(); 
        	}
        });
        $(obj).parent().parent().remove();     // 사용자가 동적 생성한 ODR DETAIL ROW삭제
    }

    /************************************************************************/
    /*                          stock Out 삭제                                                                         */
    /************************************************************************/    
    function onDel(){
        $.post(
                '/delReturnProduct.json', {  
                outNo : $("#outNo").val()
               },
            function(data) {
               if(data.result == true){
                   alert("Deleted.....!");
                   $("#reSetBtn").click();
               }else{
                   alert("ERROR!");
               }  
            });
    }
    
    /************************************************************************/
    /*                          validation 체크                             */
    /************************************************************************/
    function validation(){

        /*        var outInvoice          = $("#outInvoice").val();
        var ordDate         = $("#ordDate").val();
        var reqDate         = $("#reqDate").val();
        var schDate         = $("#schDate").val();
        
        if(outInvoice==null           || outInvoice=="") {   alert("out No: Required fields."); $("#outInvoice").focus(); return false; }
        if(outInvoice.length < 5) {   alert("out No: Enter the 5 characters"); $("#outInvoice").focus(); return false; }
        
        if( !isValidDate(ordDate,"Out Date") ){ $("#ordDate").focus(); return false; }
        if( !isValidDate(reqDate,"Requset Date") ){ $("#reqDate").focus(); return false; }
        if( !isValidDate(schDate,"Schedule Date") ){ $("#schDate").focus(); return false; }
      var ordDate         = $("#ordDate").val();
        var originCode      = $("#originCode").val();
        var originName      = $("#originName").val();
        var packingDesc     = $("#packingDesc").val();
        var reqDate         = $("#reqDate").val();
        var priceBase       = $("#priceBase").val();
        var scheduleDate    = $("#scheduleDate").val();
        var portOfLoadName  = $("#portOfLoadName").val();
        var transMethodName = $("#transMethodName").val();
 */
        
        
/*      if(ordDate==null         || ordDate=="") { alert("ordDate 입려하시오."); $("#ordDate").focus(); return false; }
        if(originCode==null      || originCode=="") { alert("originCode 입려하시오."); $("#originCode").focus(); return false; }
        if(originName==null      || originName=="") { alert("originName 입려하시오."); $("#originName").focus(); return false; }
        if(packingDesc==null     || packingDesc=="") { alert("packingDesc 입려하시오."); $("#packingDesc").focus(); return false; }
        if(reqDate==null         || reqDate=="") { alert("reqDate 입려하시오."); $("#reqDate").focus(); return false; }
        if(priceBase==null       || priceBase=="") { alert("priceBase 입려하시오."); $("#priceBase").focus(); return false; }
        if(scheduleDate==null    || scheduleDate=="") { alert("scheduleDate 입려하시오."); $("#scheduleDate").focus(); return false; }
        if(portOfLoadName==null  || portOfLoadName=="") { alert("portOfLoadName 입려하시오."); $("#portOfLoadName").focus(); return false; }
        if(transMethodName==null || transMethodName=="") { alert("transMethodName 입려하시오."); $("#transMethodName").focus(); return false; }

        if( !isValidDate(ordDate,"ordDate") ){ $("#ordDate").focus(); return false; }
        if( !isValidDate(reqDate,"reqDate") ){ $("#reqDate").focus(); return false; }
        if( !isValidDate(scheduleDate,"scheduleDate") ){ $("#scheduleDate").focus(); return false; }
        
   

        for(var i=0 ; i < $("[name=goodsCode]").length ; i++){
            var goodsCodeTmp = $("[name=goodsCode]").eq(i).val();
            var qtyTmp = $("[name=qty]").eq(i).val();
            
            if(goodsCodeTmp==null   || goodsCodeTmp=="") { alert("goodsCode: Required fields."); $("[name=goodsCode]").eq(i).focus(); return false; }
            if(qtyTmp==null         || qtyTmp=="") { alert("Quantity: Required fields."); $("[name=qty]").eq(i).focus(); return false; }
            if(qtyTmp < 1) { alert("qty: 0보다 크게 입력"); $("#qty").eq(i).focus(); return false; }
        } */  
      
      return true;      
    } 
       
    /************************************************************************/
    /*                          Dialog                                      */
    /************************************************************************/
    function viewDialogOpen(returnNo, returnDate, returnEndUserName, returnEndUser, qty, qty2, stockQty, qrYn, cause, disDate, index){
    	var remarkTmp2 = $("[name=remarkTmp]").eq(index).val();
    	var disRemarkTmp2 = $("[name=disRemarkTmp]").eq(index).val();
    	$("#pop_remark").val(remarkTmp2);
    	$("#pop_disRemark").val(disRemarkTmp2);
        $("#pop_returnNo").val(returnNo);
    	$("#pop_qty").val(qty);
    	
    	$("#pop_qtyTmp").val(qty);
    	$("#pop_qty2").val(qty2);
    	$("#pop_realsedQty").val(stockQty);
    	$("#pop_qrYn").val(qrYn);
    	$("#pop_cause").val(cause);
        $("#pop_returnDate").val(returnDate);
        $("#pop_returnEndUserName").val(returnEndUserName);
        $("#pop_returnEndUser").val(returnEndUser);
        $("#pop_disDate").val(disDate);
        $("#spanQty2").empty().html(qty2);
        //$("#pop_remark").val(remark);
        var contents = "("+remarkTmp2.length+" / ";
        $("#cnt").html(contents);
        
        var contents2 = "("+disRemarkTmp2.length+" / ";
        $("#disCnt").html(contents2);
        
        
        $("#viewDialog").dialog({
            modal:true, 
            width:500,
            title:"Detail Update"
        });
    }   

    
    function onReturnProductNoPop(){
    	window.open('/returnNoPop.html', 'returnProductNoPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }
    
    function returnProductNoPopValue(outNo, outInvoice){
    	$("#outNo").val(outNo);
        $("#outInvoice").val(outInvoice);
        view();
    }
    /************************************************************************/
    /*                  출고상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
     /* 상품 팝업 버튼 */
    var productIndex = 0;
    function onReturnProductPopup(obj){
        productIndex = $("img[id='returnProductPop']").index(obj);
        var rowId = $("[name=rowId]").eq(productIndex).val();
        
        var returnDate      = $("[name=returnDate]").eq(productIndex).val();
        
        if(returnDate==null      || returnDate=="") { alert("Return Date Required!!"); $("[name=returnDate]").focus(); return false; }
        
        $("[name=rowDetailId]").each(function(){
            if($(this).val() == rowId){
                var valCnt = $("[name=rowDetailId]").index(this);
                $(this).parent().parent().remove(); 
            }
        });
        
        window.open('/returnProductPop.html?rowId='+rowId, 'returnProductPop', 'width=630, height=670, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }
    /* 상품정보 맵핑 */
    function returnProductPopValue(arg, batchNo, returnQty2, goodsName, cause, causeText, realsedQty, endUser, endUserName, remark){
    	
    	$("[name=batchNo]").eq(productIndex).val(batchNo);
    	$("[name=returnQty]").eq(productIndex).val(returnQty2);
    	$("[name=goodsName]").eq(productIndex).val(goodsName);
    	$("[name=causeText]").eq(productIndex).val(causeText);
    	$("[name=cause]").eq(productIndex).val(cause);
    	$("[name=remark]").eq(productIndex).val(remark);
    	$("[name=realsedQty]").eq(productIndex).val(realsedQty);
    	
    	$("[name=endUser]").eq(productIndex).val(endUser);
    	$("[name=endUserName]").eq(productIndex).val(endUserName);
    	
    	$("#returnProductPopDetailHidden").append(arg);
    	
    	var rowDetailIdTmp = "";
        var rowDetailIdCnt = "";
        var rowIdTmp = "";
        var rowIdCnt = "";
        $("[name=rowDetailId]").each(function(){
            rowDetailIdTmp = $(this).val();
            rowDetailIdCnt = $("[name=rowDetailId]").index(this);
            $("[name=rowId]").each(function(){
                rowIdTmp = $(this).val();
                rowIdCnt = $("[name=rowId]").index(this);
                if(rowDetailIdTmp == rowIdTmp){                         
                    $("[name=returnDateDetail]").eq(rowDetailIdCnt).val($("[name=returnDate]").eq(rowIdCnt).val());
                    $("[name=causeDetail]").eq(rowDetailIdCnt).val($("[name=cause]").eq(rowIdCnt).val());
                    $("[name=remarkDetail]").eq(rowDetailIdCnt).val($("[name=remark]").eq(rowIdCnt).val());
                    $("[name=endUserDetail]").eq(rowDetailIdCnt).val($("[name=endUser]").eq(rowIdCnt).val());
                }
            });
            /*if($(this).val() == rowId){
                var valCnt = $("[name=rowDetailId]").index(this);
                $(this).parent().parent().remove(); 
            }*/
        });
        $("form[name='outFrm']").submit();
    }

    /************************************************************************/
    /*                      고객 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 고객 팝업 버튼 */
    //var customerIndex = 0;
    function customerPopCall(obj, type){
    	popType = type; 

    	//customerIndex = $("img[id='customerPop']").index(obj);
    	if(type == 'M'){
    		window.open('/customerPop.html?customer=2', 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    	}else{
    		window.open('/customerPop2.html?customer=3', 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    	}
    }
    
    /* 고객정보 맵핑 */
    function customerPopValue(custCode , custName , addr1 , addr2, tel, fax){  
    	 switch(popType){
         case "S":
		       $("[name=sReturnEndUser]").val(custCode);
		       $("[name=sReturnEndUserName]").val(custName); 
		       break;
         case "P":
	           $("#pop_returnEndUser").val(custCode);
	           $("#pop_returnEndUserName").val(custName); 
        	   break;
         case "M":
             $("#sMessrs").val(custCode);
             $("#sMessrsName").val(custName); 
             break;
         }
           popType = "";
    };
    
    /************************************************************************/
    /*                      상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 상품 팝업 버튼 */
    function onProductPopup(obj){
        var custCodeTmp = "";
        if($("#roleId").val() == "3"){
            custCodeTmp = $("#custCodeUser").val();
        }
        window.open('/productPop.html?custCode='+custCodeTmp, 'changeProductPop', 'width=615, height=450, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }

    function productPopValue(goodsCode, goodsName, unit, boxQty, hsCode, productCode, custCode, custName){

        $("#sGoodsCode").val(goodsCode);
        $("#sGoodsName").val(goodsName);   
    }
    
    function qtyChange(){
    	var pop_qty = $("#pop_qty").val();
    	var pop_qty2 = $("#pop_qty2").val();
    	if(parseInt(pop_qty) > parseInt(pop_qty2)){
    		alert("Not enough!!");
    		$("#pop_qty").val($("#pop_qtyTmp").val());
    		$("#pop_qty").focus();
    		return;
    	}
    }

</script>
</head>


<body>
<div class="wrap">
    <div class="pagetitle">
        <h1>STOCK DISCREPANCY AND RETURNED STOCK</h1>
    </div>
    <div class="">
    <!-- 레이어 팝업시작 -->
        <div id="viewDialog" style="display: none; background: white;">
         <input type="hidden" id="pop_odrDetailSeq">
           <table class="TableST">
             <tr>
               <th>Return Date</th>
               <td><input type="text" name="pop_outDate" id="pop_returnDate" class="inSTR50" maxlength="20" readonly/></td>
              </tr>
             <tr>
               <th>End User Name</th>
               <td><input type="text" name="pop_vihicleNo" id="pop_returnEndUserName" class="inSTR50" maxlength="20" readonly/>
               <input type="hidden" name="pop_outNo" id="pop_returnNo"/>
               <input type="hidden" name="pop_outNo" id="pop_returnEndUser"/>
               <img alt="Search" height="16" onclick="customerPopCall(this, 'P')" src='/images/web/bkn_zoom.gif' align='absmiddle'>
               </td>
              </tr>
              <tr>
               <th>QTY</th>
               <td><input type="text" name="pop_qty" id="pop_qty" class="inST50" maxlength="10" onBlur="qtyChange();" onkeydown='onlyNum(event);'/> / <span id="spanQty2"></span>
               <input type="hidden" name="pop_qty2" id="pop_qty2"/><input type="hidden" name="pop_qtyTmp" id="pop_qtyTmp"/></td>
              </tr>
              <tr>
               <th>Realsed by QA QTY</th>
               <td><input type="text" name="pop_realsedQty" id="pop_realsedQty" class="inST50" maxlength="10" onkeydown='onlyNum(event);'/></td>
              </tr>
              <tr>
               <th>QR YN</th>
               <td>
                <select name="pop_qrYn" id="pop_qrYn">
                    <option value="">select</option>
                    <option value="Y">Y</option>
                    <option value="N">N</option>
                </select>
               </td>
              </tr>
              <tr>
                <th>CAUSE</th>
	            <td>
	                <select name="pop_cause" id="pop_cause">
	                    <option value="">select</option>
	                    <c:forEach items="${requestScope.listReturnCause}" var="listReturnCauseList">
	                    <option value="${listReturnCauseList.returnCode}">${listReturnCauseList.returnName }</option>
	                  </c:forEach>
	                </select>
	            </td>
	          </tr>
              <tr>
		         <th>Remarks<br><span id="cnt">(0 / </span>1000)</th>
		         <td colspan="3"><textarea class="teST80" wrap="virtual" id="pop_remark" name="pop_remark"></textarea></td>
		      </tr>
		      <tr>
               <th>Disposal Date</th>
               <td><input type="text" name="pop_disDate" id="pop_disDate" class="inSTR50" maxlength="20" readonly/></td>
              </tr>
             <tr>
             <tr>
                 <th>Disposal Remarks<br><span id="disCnt">(0 / </span>1000)</th>
                 <td colspan="3"><textarea class="teST80" wrap="virtual" id="pop_disRemark" name="pop_disRemark"></textarea></td>
              </tr>
           </table>
           <div class="bo_btn">
                <ul class="btnst"><li class="a"><a href="javascript:modifyReturnProductDetail();" id="save" >SAVE</a></li></ul>
           </div>  
       </div>
    <!-- 레이어 팝업끝 -->   
       
    <form name="outFrm" method="post" action="/saveReturnProduct.json"> <%--리턴값 json으로 설정 --%>
    <input type="hidden" id ="saveStatus" name="saveStatus" value="SAVE" />     <%-- 조회, 수정, 초기화, 최초 입력 시 필요 (최초, 초기화 후 = SAVE   ,  수정, 조회 후 = UPDATE)--%>
    
        <table class="TableST">
            <tr>
                <th width="15%">End User</th>
                <td width="35%">
                    <input type="text" class="inSTR80" id="sReturnEndUserName" name="sReturnEndUserName" maxlength="20"/>
                    <input type="hidden" id="sReturnEndUser" name="sReturnEndUser" />
                    <img alt="Search" hight="16" width="16" id="sEndUserPop" onclick="customerPopCall(this, 'S')" src="/images/web/bkn_zoom.gif">
                </td>
                <th width="15%">Messrs</th>
                <td width="35%">
                    <input type="text" class="inSTR80" id="sMessrsName" name="sMessrsName" maxlength="20"/>
                    <input type="hidden" id="sMessrs" name="sMessrs" />
                    <img alt="Search" hight="16" width="16" id="sMessrsPop" onclick="customerPopCall(this, 'M')" src="/images/web/bkn_zoom.gif">
                </td>
            </tr>
            <tr>
                <th width="15%">Goods</th>
                <td width="35%">
                    <input type='text' class='inSTR80' name='sGoodsName' id='sGoodsName'/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='productPop' onclick='onProductPopup(this);'>
                    <input type='hidden' class='inSTR95' name='sGoodsCode' id='sGoodsCode'/>
                </td>
                <th>Batch</th>
                <td>
                    <input type="text" class="inST80" name="lotNo" id="lotNo"/>                    
                </td>
            </tr>
            <tr>
                <th width="15%">Return Start Date</th>
                <td width="35%">
                    <input type="text" class="inSTR50" id="sReturnStartDate" name="sReturnStartDate" maxlength="5" value=""/>
                </td>
                <th width="15%">Return End Date</th>
                <td width="35%">
                    <input type="text" class="inSTR50" id="sReturnEndDate" name="sReturnEndDate" maxlength="5" value=""/>
                </td>
            </tr>
        </table>
        <div class="bo_btnS" id="bo_btnS" style="display: block;">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </div>
        <br/><br/><br/><br/>
        <div class="bo_btn" id="bo_btn_add" style="display: block;">
            <span id="addRow"><ul class="btnst"><li class="a"><a href="#" id="detailAddRow" >ADD</a></li></ul></span>
        </div>
        <div class="taHeadW">
            <table class="TableST2Head" >
                <tr>
                    <th width="5%">No</th>
                    <th width="13%">Return Date</th>
                    <th width="15%">Goods Name</th>
                    <th width="10%">Batch</th>
                    <th width="8%">Return <br>Qty</th>                    
                    <th width="15%">End User Name</th>
                    <th width="10%">Cause</th>
                    <th width="7%">Realsed by <br>QA Qty</th>
                    <th width="7%">U / D</th>
                </tr>
            </table>
        </div>
        <div class="taBodyW4">
            <table class="TableST2Body" id="outDetailTable">
            </table>
        </div>
        <div id="viewDialog2">
        <table class="TableST4" style="display: none; background: white;">
            <tr>
                <th>code</th>
                <th>NAME</th>
                <th>MAWB</th>
                <th>HAWB</th>
                <th>Batch</th>
                <th>STOCK<br>OUT QTY</th>
            </tr>
            <span id="returnProductPopDetailHidden">
                <tr>
                   <td colspan="10"></td>    
                </tr>
            </span>                    
        </table>
        </div>    
        <br />
    </div>
    <table class="TableST5">
        <tr>
            <th>Remarks</th>
            <td><textarea class="teST80" wrap="virtual" id="remark" name="remark" style="background:#eeeeee" readonly></textarea></td>
        </tr>      
    </table>
    <div class="bo_btn" id="bo_btn" style="display: block;">
        <ul class="btnst"><li class="a"><a href="#" id="reSetBtn" >INIT</a></li></ul>
        <!-- ul class="btnst"><li class="a"><a href="#" id="saveBtn" >SAVE</a></li></ul-->
    </div>
    <input type="hidden" name="roleId" id="roleId" value="${requestScope.roleId}">
    </form>
</div>
</body>
</html>